import request from "@/util/http";
import qs from "qs";

export default {
  //渲染页面接口
  gain(forms) {
    return request({
      method: "get",
      params: {
        _gp: "admin.goods",
        _mt: "list",
        categoryId: forms.categoryId,
        page: forms.pageNo,
        limit: forms.limit,
        title: forms.title,
        status: forms.status,
        barcode: forms.barcode
      }
    });
  },
  //spu树
  spu() {
    return request({
      method: "get",
      params: {
        _gp: "admin.category",
        _mt: "categoryTree"
      }
    });
  },
  //查看
  look(id) {
    return request({
      method: "get",
      params: {
        _gp: "admin.goods",
        _mt: "detail",
        spuId: id //商品id
      }
    });
  },
  //新增
  adduser(form) {
    return request({
      method: "post",
      data: qs.stringify({
        _gp: "admin.goods",
        _mt: "create",
        spuDTO: JSON.stringify({
          title: form.title, //商品名称
          originalPriceRaw: form.originalPriceRaw * 100, //原始价格
          priceRaw: form.priceRaw * 100, //当前价格
          vipPriceRaw: form.vipPriceRaw * 100, //VIP价格
          originalPrice: form.originalPriceRaw * 100, //原始价格
          price: form.priceRaw * 100, //当前价格
          vipPrice: form.vipPriceRaw * 100, //VIP价格
          stock: form.stock, //剩余库存
          freightTemplateId: form.freightTemplateId, //运费模板
          status: form.status, //是否在售
          imgList: form.imgList, //商品图片  img
          img: form.img,
          unit: form.unit, //商品单位
          categoryId: form.categoryId, //所属类目 categoryId
          description: form.description, //商品简介
          detail: form.detail, //商品详细介绍
          skuList: form.skuList, //商品类型
          attributeList: form.attributeList //商品参数 attributeList
        })
      })
    });
  },
  //删除接口
  cancel(form) {
    return request({
      method: "post",
      data: qs.stringify({
        _gp: "admin.goods",
        _mt: "delete",
        spuId: form.id //商品id
      })
    });
  },
  //批量删除
  batchCancel(form) {
    return request({
      method: "post",
      data: qs.stringify({
        _gp: "admin.goods",
        _mt: "batchDelete",
        ids: JSON.stringify(form.ids)
      })
    });
  },
  //编辑角色
  compile(form) {
    return request({
      method: "post",
      data: qs.stringify({
        _gp: "admin.goods",
        _mt: "edit",
        spuDTO: JSON.stringify({
          title: form.title, //商品名称
          originalPriceRaw: form.originalPriceRaw / 100, //原始价格
          priceRaw: form.priceRaw / 100, //当前价格
          vipPriceRaw: form.vipPriceRaw / 100, //VIP价格
          originalPrice: form.originalPriceRaw * 100, //原始价格
          price: form.priceRaw * 100, //当前价格
          vipPrice: form.vipPriceRaw * 100, //VIP价格
          stock: form.stock, //剩余库存
          freightTemplateId: form.freightTemplateId, //运费模板
          status: form.status, //是否在售
          imgList: form.imgList, //商品图片  img
          img: form.img,
          unit: form.unit, //商品单位
          categoryId: form.categoryId, //所属类目 categoryId
          description: form.description, //商品简介
          detail: form.detail, //商品详细介绍
          skuList: form.skuList, //商品类型
          attributeList: form.attributeList, //商品参数 attributeList
          id: form.id
        })
      })
    });
  },
  //冻结接口
  freeze(form, status) {
    return request({
      method: "post",
      data: qs.stringify({
        _gp: "admin.goods",
        _mt: "freezeOrActivation",
        spuId: form.id, //商品id
        status: status
      })
    });
  },
  //获取到运费模板
  batch() {
    return request({
      method: "get",
      params: {
        _gp: "admin.freight",
        _mt: "getAllFreightTemplate"
      }
    });
  }
};
